<template>
  <div>
    <!-- <Add ref="add" v-if="companyLevel.length > 0" :companyLevel="companyLevel" @ok="search"></Add> -->
    <Setting ref="Setting" @ok="search"></Setting>
    <!-- <Authorization ref="authorization" v-if="isShowAuth" @ok="search"></Authorization> -->
    <ZgNewPage
      ref="page"
      :title="pageTitle"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :dataBtns="dataBtns"
      :extraBtns="extraBtns"
      :headers="headers"
      :conditions="conditions"
      :adminWidth="100"
      :scrollX="1500"
      @search="onSearch"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
      @extra="toExtra"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h,i) in headers"
          :key="`column${i}`"
          :width="h.width===0 ? 'auto' : h.width"
          align="center"
          :title="h.label">
          <template slot-scope="record">
            <template v-if="h.code == 'type'">
              <ZgDicHolder :code="record[h.code]" parentCode="userType"/>
            </template>
            <template v-else-if="h.code == 'authStatue'">
              {{ record[h.code] ? '已认证' : '未认证' }}
            </template>
            <template v-else>{{ record[h.code] }}</template>
          </template>
        </a-table-column>
      </template>
      <template slot="thMode" slot-scope="scope">
        <a-row :gutter="10">
          <a-col :span="4" v-for="t in scope.list" :key="`thMode_${t.id}`">
            <a-card class="mb10">
              <div class="wfull h100 scroll">
                {{ t }}
              </div>
            </a-card>
          </a-col>
        </a-row>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>

// import Add from './Add'
import Setting from './setting'
// import Authorization from './Authorization'
export default {
  components: {
    // Add,
    Setting,
    // Authorization
  },
  data () {
    return {
      pageTitle: '默认归档配置',
      uniqueName: 'test',
      pageOpt: {
        showConditionBtn: true,
        showHeaderConfig: true,
        showAttachBtn: true,
        showPageTitle: false
      },
      conditions: [
        { code: 'name', compType: '单行文本', label: '表单名称', defaultVal: '' },
        { code: 'value', compType: '单行文本', label: '表单类型', defaultVal: '' },
      ],
      headers: [
        { code: 'name', label: '表单名称', isShow: true, sort: 0 },
        { code: 'value', label: '表单编号', isShow: true, sort: 0 },
        { code: 'authStatue', label: '关联关系', isShow: true, sort: 0 },
        { code: 'intro', label: '表单描述', isShow: true, sort: 0 }
      ],
      dataBtns: [
        // { key: 1, name: '编辑', type: 'link', isShow: () => { return true } },
        // { key: 2, name: '删除', type: 'link', isShow: () => { return true } },
        { key: 3, name: '配置', type: 'link', isShow: () => { return true } },
      ],
      extraBtns: [
        { key: 1, name: '新增', icon: 'plus-circle', type: 'primary' }
      ],
      companyLevel: [],
      isShowAuth: false
    }
  },
  mounted () {
  },
  methods: {
    search () {
      this.$refs.page.search()
    },
    onSearch (param) {
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }

      this.getList(param)
    },
    getList (param) {
      const paramObj = {
        search: {
          name: param.name, // 查询条件：表单类型名称
          value: param.value, // 查询条件：表单类型
        },
        paramMap: {
          page: 1,
          rows: 50
        }
      }

      this.$http.post('/swan-cloud-settle-its/intellectFormManage/selectAllFormType', paramObj).then(res => {
          if (res.code === 200) {
            const list = res.data.records
            this.$refs.page.endSearch({
              total: list.length,
              list: list
            })
          }
      })
    },
    onFilter (f, param) {
    },
    toAdmin (param) {
      if (param.key === 1) {

      } else if (param.key === 2) {

      } else if (param.key === 3) {
        this.$refs.Setting.open(param)
      }
    },
    toExtra (opt) {
      this.$refs.add.open()
    },
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders.filter(t => {
        return t.isShow
      }).sort((a, b) => {
        return a.sort - b.sort
      })
    },

  }
}
</script>

<style lang="scss" scoped>
</style>
